Ext.define('DragonApp.view.monster.FilterBar', {
    extend: 'Ext.toolbar.Toolbar',
    xtype: 'monster-filter',

    controller: 'monster',

    items: [{
        xtype: 'radiogroup',
        fieldLabel: '筛选条件',

        defaultType: 'radiofield',
        itemId: 'conditions',
        defaults: {
            width: 130
        },
        items: [{
            boxLabel: '不限',
            name: 'monster_filter',
            inputValue: 'unlimited',
            checked: true
        }, {
            boxLabel: '定位',
            name: 'monster_filter',
            inputValue: 'location'
        }, {
            boxLabel: '品质',
            name: 'monster_filter',
            inputValue: 'quality'
        }, {
            boxLabel: '怒气',
            name: 'monster_filter',
            inputValue: 'need_angry'
        }, {
            boxLabel: '星级',
            name: 'monster_filter',
            inputValue: 'level'
        }],
        listeners: {
            change: {

                fn: function() {

                    var LocationGroup = Ext.create('DragonApp.view.monster.filter.LocationGroup', {});
                    var QualityGroup = Ext.create('DragonApp.view.monster.filter.QualityGroup', {});
                    var AngryGroup = Ext.create('DragonApp.view.monster.filter.AngryGroup', {});
                    var LevelGroup = Ext.create('DragonApp.view.monster.filter.LevelGroup', {});

                    QualityGroup.setValue('0');
                    AngryGroup.setValue('0');
                    LevelGroup.setValue('0');
                    LocationGroup.setValue('0');

                    var grid = Ext.ComponentQuery.query('monstergrid')[0];

                    //清空细分
                    var filter_items = grid.queryById('filter-items');
                    filter_items.removeAll();

                    var store = Ext.data.StoreManager.lookup('jsonPmonsterStore');

                    var value = this.getValue().monster_filter;

                    switch (value) {
                        case 'unlimited':
                            store.clearFilter();
                            break;
                        case 'location':
                            store.clearFilter();
                            filter_items.add(LocationGroup);
                            break;
                        case 'quality':
                            store.clearFilter();
                            filter_items.add(QualityGroup);
                            break;
                        case 'need_angry':
                            store.clearFilter();
                            filter_items.add(AngryGroup);
                            break;
                        case 'level':
                            store.clearFilter();
                            filter_items.add(LevelGroup);
                            break;
                    }
                }
            }
        }
    }, '->', {
        xtype: 'textfield',
        name: 'searchfield',
        itemId: 'search_field',
        emptyText: '请输入佣兵名称',
        listeners: {
            specialKey: 'onTextFieldSpecialKeySearch',
            change: 'onTextFieldClear'
        }
    }, {
        xtype: 'button',
        itemId: 'search_btn',
        text: '搜索',
        reference: 'search',
        iconCls: 'fa fa-search fa-lg buttonIcon',
        listeners: {
            click: 'onSearch'
        }
    }]
});